package main

import (
	"fmt"
	"sort"
)

func main() {
	nums := []int{4, 4, 7, 6, 7}
	res := minSubsequence(nums)
	fmt.Println(res)
}

func minSubsequence(nums []int) []int {
	items := make([]Item, 0)
	sum := 0
	for i, num := range nums {
		items = append(items, Item{num, i})
		sum += num
	}
	sort.Slice(items, func(i, j int) bool {
		return items[i].num < items[j].num
	})
	curSum := 0
	for i := len(items) - 1; i >= 0; i-- {
		curSum += items[i].num
		if curSum > sum/2 {
			items = items[i:]
			break
		}
	}
	//sort.Slice(items, func(i, j int) bool {
	//	return items[i].index < items[j].index
	//})
	var res []int
	for i := len(items) - 1; i >= 0; i-- {
		res = append(res, items[i].num)
	}
	return res
}

type Item struct {
	num   int
	index int
}
